package org.jeecg.modules.wlhy.utils;

import org.jeecg.common.constant.PayConstants;
import org.jeecg.modules.wlhy.setting.entity.HySetting;
import org.jeecg.modules.wlhy.setting.service.IHySettingService;
import org.jeecg.modules.wlhy.walletcfg.service.IHyWalletCfgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author yangqf
 * @date 2023/4/28 21:16
 * 支付工具类
 */
@Component
public class BankPayUtil {
    private static BankPayUtil bankPayUtil;
    @Autowired
    private IHySettingService settingService;
    @Autowired
    private IHyWalletCfgService walletCfgService;
    @PostConstruct
    public void init() {
        bankPayUtil=this;
    }


    /**
     * 系统支付功能是否开启
     * @return
     */
    public static boolean checkSetting() {
        HySetting settingValue = bankPayUtil.settingService
                .lambdaQuery().eq(HySetting::getTag, "bank_relative")
                .one();
        if("1".equals(settingValue.getData())) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 验证支付密码
     * @return
     */
    public static boolean checkPwd(String uid, String pwd) {
        return bankPayUtil.walletCfgService.checkPwd(pwd, uid);
    }

    /**
     * 验证订单模式
     * @param orderMode
     * @return
     */
    public static boolean checkOrderMode(String orderMode) {
        if (!PayConstants.ORDER_MODE.MANAGE_FEE.equals(orderMode) && !PayConstants.ORDER_MODE.DIFF_PRICE.equals(orderMode)&&!PayConstants.ORDER_MODE.CUSTOMER_MODE.equals(orderMode)) {return false;
        }
        return true;
    }

    /**
     * 验证支付方式
     * @param payType
     * @return
     */

    public static boolean checkPayType(String payType) {
        if (!PayConstants.PAY_TYPE.BY_ORDER.equals(payType) && !PayConstants.PAY_TYPE.BY_CARRIER.equals(payType) && !PayConstants.PAY_TYPE.BY_PREPAY.equals(payType)) {
            return false;
        } else {
            return true;
        }
    }



}
